package com.adgox.tiantianbiting.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.adgox.tiantianbiting.R;
import com.adgox.tiantianbiting.bean.SubProgramBean;
import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by tang on 2018/12/25.
 */

public class HotAdapter extends RecyclerView.Adapter<HotAdapter.ViewHolder> implements View.OnClickListener {

    private List<SubProgramBean> datas;

    public HotAdapter(List<SubProgramBean> datas) {
        this.datas = datas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_hot, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Glide.with(holder.itemView.getContext()).load(datas.get(position).getShareImageUrl()).into(holder.imgProgram);
        holder.tvTitle.setText(datas.get(position).getTitle());
        holder.tvSubTitle.setText(datas.get(position).getDescribe());
        holder.tvListenNum.setText(""+datas.get(position).getListenNum());
        holder.tvSeriesNum.setText(datas.get(position).getTotalSeason()+"集");

        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.img_program)
        ImageView imgProgram;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_sub_title)
        TextView tvSubTitle;
        @BindView(R.id.tv_listen_num)
        TextView tvListenNum;
        @BindView(R.id.tv_series_num)
        TextView tvSeriesNum;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            itemView.setOnClickListener(HotAdapter.this);
        }
    }

    public interface OnItemClickListener{
        void onHotItemClick(View view,int position);
    }

    public OnItemClickListener listener = null;

    public void setOnItemClick(OnItemClickListener listener){
        this.listener = listener;
    }

    @Override
    public void onClick(View view) {
        int positon = (int) view.getTag();
        if (listener != null){
            listener.onHotItemClick(view,positon);
        }
    }

}
